﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Abp.Authorization.Users;
using Abp.Domain.Entities;
using Abp.Domain.Entities.Auditing;
using Abp.MultiTenancy;
using XHD.WXZJ.Departments;

namespace XHD.WXZJ.Posts
{
    public class Posts<TTenant, TDepartment, TUser> : PostsBase, IFullAudited<TUser>, IAudited<TUser>, IMayHaveTenant<TTenant, TUser>
        where TTenant : AbpTenant<TTenant, TUser>
        where TDepartment:AbpDepartment<TTenant,TUser> 
        where TUser : AbpUser<TTenant, TUser>
    {
        /// <summary>
        /// 显示名称长度
        /// </summary>
        public const int MaxDisplayNameLength = 255;

        /// <summary>
        /// 名称校验规则
        /// </summary>
        public const string PostNameRegex = "^[a-zA-Z][a-zA-Z0-9_-]{1,}$";

        /// <summary>
        /// The Tenant, if this Department is a tenant-level role.
        /// 
        /// </summary>
        [ForeignKey("TenantId")]
        public virtual TTenant Tenant { get; set; }

         [ForeignKey("DepartmentId")]
        public virtual TDepartment Department { get; set; }

        [Required]
        [StringLength(255)]
        public virtual string DisplayName { get; set; }

        public virtual string Icon { get; set; }

        public virtual int IsValid { get; set; }

        public virtual TUser DeleterUser { get; set; }

        public virtual TUser CreatorUser { get; set; }

        public virtual TUser LastModifierUser { get; set; }

        public virtual ICollection<PostUser> Users { get; set; }
        /// <summary>
        /// 构造函数
        /// </summary>
        public Posts()
        {
            Name = Guid.NewGuid().ToString("N");
        }

        public Posts(int? tenantId, int departmentId, string displayName)
            : this()
        {
            TenantId = tenantId;
            DisplayName = displayName;
            DepartmentId = departmentId;
        }



        public Posts(int? tenantId, int departmentId, string name, string displayName) :
            this(tenantId,departmentId, displayName)
        {
            Name = name;
           
        }

        public override string ToString()
        {
            return string.Format("[岗位 {0}, 名称={1}]", (object)this.Id, (object)this.Name);
        }
    }
}
